import os
import json
from pyprojroot import here
from openai import OpenAI

prompt = """
Consideration proudct : ⼯⼚现货PVC充⽓⻘蛙夜市地摊热卖充⽓玩具发光蛙⼉童⽔上玩具
1. Compose human readale product title used on Amazon in english within 20 words 
2. Write 5 selling points for the products in Amazon.
3. Evaluate a price range for this product in U.S.

Output the result in json format with three properties called title, selling_points and price_range
"""

def get_response(prompt, config):
    client = OpenAI(
        base_url = config['base_url'],
        api_key = config['api_key'],
    )
    completions = client.chat.completions.create (
        model=config['model'],
        messages=[{
            'role': 'user',
            'content': prompt
        }],
        max_tokens=512,
        n=1,
        stop=None,
        temperature=0.0,        
    )
    message = completions.choices[0].message.content
    return message

def load_config():
    config_file = here('config.json')
    with open(config_file, 'r', encoding='utf-8') as f:
        config = json.load(f)
            
    return config

def main():
    config = load_config()
    print(get_response(prompt, config))


if __name__ == "__main__":
    main()
